#pragma once
#include <list>
#include <string>
#include <set>
#include<typeinfo>
#include "LogUtils.h"
typedef unsigned int UINT;
struct ChildNode
{
	char c;
	UINT n;
public:
	ChildNode(char c,UINT n):c(c),n(n){}
	virtual ~ ChildNode(){
	}
};
struct ParentNode:public ChildNode
{
	ChildNode *left,*right;

public:
	ParentNode( ChildNode *left, ChildNode *right):ChildNode(0,left->n+right->n),left(left),right(right){}

};
struct RootNode
{
	ChildNode *root;
	~RootNode()
	{
		deleteNode(root);
	}
	
	void deleteNode(ChildNode *node)
	{
		if((typeid(*node)==typeid(ParentNode)))
		{
			ParentNode *p = (ParentNode*)node;
			deleteNode(p->left);
			deleteNode(p->right);
			delete p;
		}
		else
		{
			delete node;
		}
	}
};
struct CodeTable
{
	std::string code;
	ChildNode *node;

};





RootNode* buildTree(const char *);
std::list<CodeTable*> * makeTable(RootNode* &);
std::string transcoding(std::list<CodeTable*> * &table,const char *c);
std::string decoding(RootNode* &,const char *c);